package estimators.numberoOfDocuments;

import distributedRE.model.QueryDatabase;

public class LindstonCorrectionEstimator extends NumberOfDocumentCalculator {

	private double correction;

	public LindstonCorrectionEstimator(double correction){
		this.correction = correction;
	}
	
	protected double getMustNotProbability(String term, QueryDatabase qdb) {

		long frequency = qdb.getFrequency(term,false);
		
		long size = qdb.getNumberOfDocuments();
		
		long q_size = qdb.getQuery().getSize();
		
		return ((double)(size - frequency) + correction)/((double)size + correction*(double)q_size);
		
	}

	@Override
	protected double getMustProbability(String term, QueryDatabase qdb) {
		
		long frequency = qdb.getFrequency(term,true);
		
		long size = qdb.getNumberOfDocuments();
		
		long q_size = qdb.getQuery().getSize();
		
		return ((double)frequency + correction)/((double)size + correction*(double)q_size);
		
	}

	public String toString(){
		return "Lindston Correction Estimator with a correction value of: " + correction; 
	}
	
}
